﻿<%@ Page Language="C#" MasterPageFile="~/MasterPage/IQCare.master" AutoEventWireup="true"
    CodeFile="frmClinical_CustomForm.aspx.cs" Inherits="frmClinical_CustomForm" Title="Untitled Page"
    MaintainScrollPositionOnPostback="true" EnableEventValidation="false" %>

<%@ Register Assembly="AjaxControlToolkit" TagPrefix="act" Namespace="AjaxControlToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="IQCareContentPlaceHolder" runat="Server">
    <%--<head>--%>
    <%-- <link rel="stylesheet" type="text/css" href="../Style/StyleSheet.css" />
    <link type="text/css" href="../Style/_assets/css/grid.css" rel="stylesheet" />
    <link type="text/css" href="../Style/_assets/css/round.css" rel="stylesheet" />--%>
    <%--</head>--%>
    <div style="padding-top: 1px; padding-left: 10px; padding-right: 10px; padding-bottom: 10px">
        <asp:ScriptManager ID="mst" runat="server">
        </asp:ScriptManager>
        <script language="javascript" type="text/javascript">
            function WindowPrint() {
                  window.print();
            }
            function WindowPrintAll() {
            window.print();
            }

            function OpenPharmacyDialog(DrgId) {
                window.open('../Pharmacy/frmDrugSelector.aspx?DrugType=' + DrgId + '&BtnDrg=customfrmDrug', 'DrugSelection', 'toolbars=no,location=no,directories=no,dependent=yes,top=10,left=30,maximize=no,resize=no,width=700,height=350,scrollbars=yes');
            }

            function OpenRegimenDialog(DrgId, ControlId) {
                window.open('../Pharmacy/frmDrugSelector.aspx?RegType=' + DrgId + '&BtnRegimen=customfrmReg&Cntrl=' + ControlId + '', 'DrugSelection', 'toolbars=no,location=no,directories=no,dependent=yes,top=10,left=30,maximize=no,resize=no,width=700,height=350,scrollbars=yes');
            }
            function AdditionalLab() {
                window.open('../Laboratory/frmLabSelector.aspx?Mode=All', 'LabSelection', 'toolbars=no,location=no,directories=no,dependent=yes,top=10,left=30,maximize=no,resize=no,width=700,height=350,scrollbars=yes');
            }
            function ICD10PopUp(FieldId, VisitId) {
                window.open('frmClinicalICD10Selector.aspx?Param=' + FieldId + ' &Param1=' + VisitId + '', 'ICD10Selection', 'toolbars=no,location=no,directories=no,dependent=yes,top=30,left=70,maximize=no,resize=no,width=950,height=470,scrollbars=yes');
            }
            function GetControl() {
                document.forms[0].submit();
            }
            function SetValue(theObject, theValue) {
                document.getElementById('ctl00_IQCareContentPlaceHolder_' + theObject).value = theValue;
                document.forms[0].submit();
            }

            function SendCodeName(str) {
                var id = document.getElementById(str).value;
                if (id.length <= 0) {
                    return false;
                }
                else {
                    CallServer(id, "This is context from client");
                    return true;
                }
            }
            function ReceiveServerData(args, context) {
                //confirm(args);
                if ((!(args == '')) && (window.ActiveXObject)) {
                    var obj = new ActiveXObject("MSXML2.DOMDocument");
                    obj.loadXML(args);

                    try {
                        var dsRoot = obj.documentElement;
                        for (var i = 0; i < dsRoot.childNodes.length; i++) {
                            var ID = dsRoot.childNodes(i).childNodes(0).firstChild.text;
                            var Value = dsRoot.childNodes(i).childNodes(1).firstChild.text;
                            var type = dsRoot.childNodes(i).childNodes(2).firstChild.text;
                            if ((Value == 0) && (type != 'DropDown')) {
                                document.getElementById('ctl00_IQCareContentPlaceHolder_' + ID).value = '';
                            }
                            else {
                                document.getElementById('ctl00_IQCareContentPlaceHolder_' + ID).value = Value;
                            }

                        }
                    }
                    catch (err) {
                    }
                }

            }

            function CallMe(src) {
                var ctrl = document.getElementById(src).value;
                // call server side method
                //alert(ctrl);
            }
            function OpenTreeViewPopup(param1, param2) {
                var val1 = document.getElementById('ctl00$IQCareContentPlaceHolder$' + param1).value;
                var val = param1 + '%' + param2;
                window.open('frmClinicalTreeviewICDCode.aspx?param=' + val + '&ParamValue=' + val1 + '', '', 'toolbars=no,location=no,directories=no,dependent=yes,top=300,left=400,maximize=no,resize=no,width=600,height=500,scrollbars=yes');
            }

            function DataEncounter() {
                document.getElementById('Img8').disabled = true;
                document.getElementById('<%=txtvisitDate.ClientID%>').disabled = true;
            }
            function isNumberKey(evt) {
                var charCode = (evt.which) ? evt.which : event.keyCode
                if (charCode > 31 && (charCode < 48 || charCode > 57))
                    return false;

                return true;
            }



            function ClearTabData(TabId) {
                var elem = document.getElementById("<%= divhidden.ClientID %>").childNodes;
                for (var i = 0; i < elem.length; i++) {
                    if (elem[i].type == "text") {
                        var TabArray = document.getElementById(elem[i].id).id.split(/-/);
                        var TabArray1 = document.getElementById(elem[i].id).id.split(/_/);
                        if (TabArray[4] == TabId) {
                            if (document.getElementById(elem[i].id).value != '0') {
                                document.getElementById(elem[i].id).value="";
                            }
                        }
                    }

                    else if (elem[i].type == "radio") {
                        var TabArray = document.getElementById(elem[i].id).id.split(/-/);
                        if (TabArray[4] == TabId) {
                            if (document.getElementById(elem[i].id).checked == true) {
                                document.getElementById(elem[i].id).checked = false;
                            }
                        }
                    }
                    else if (elem[i].childNodes.length > 0) {
                        if (elem[i].childNodes[0].type == "checkbox") {
                            var TabArray = document.getElementById(elem[i].childNodes[0].id).id.split(/_/);
                            if (TabArray[3] == TabId) {
                                if (document.getElementById(elem[i].childNodes[0].id).checked == true) {
                                    document.getElementById(elem[i].childNodes[0].id).checked = false;
                                }
                            }
                        }
                    }

                }
                
            }

            function StringASCII(TabId) {
                var elem = document.getElementById("<%= divhidden.ClientID %>").childNodes;
                var TabData = "";
                for (var i = 0; i < elem.length; i++) {
                    if (elem[i].type == "text") {
                        var TabArray = document.getElementById(elem[i].id).id.split(/-/);
                        if (TabArray[4] == TabId) {
                            if (document.getElementById(elem[i].id).value != '0') {
                                TabData = TabData + document.getElementById(elem[i].id).value;
                            }
                        }
                    }

                    else if (elem[i].type == "radio") {
                        var TabArray = document.getElementById(elem[i].id).id.split(/-/);
                        if (TabArray[4] == TabId) {
                            if (document.getElementById(elem[i].id).checked == true) {
                                TabData = TabData + document.getElementById(elem[i].id).value;
                            }
                        }
                    }
                    else if (elem[i].childNodes.length > 0) {
                        if (elem[i].childNodes[0].type == "checkbox") {
                            var TabArray = document.getElementById(elem[i].childNodes[0].id).id.split(/_/);
                            if (TabArray[3] == TabId) {
                                if (document.getElementById(elem[i].childNodes[0].id).checked == true) {
                                    TabData = TabData + document.getElementById(elem[i].childNodes[0].id).value;
                                }
                            }
                        }
                    }

                }
                document.getElementById("<%= hdnStringASCIIValue.ClientID%>").value = TabData;
            }

            function ValidateSave(sender, args) {

                var PrevTabName = document.getElementById("<%=hdnPrevTabName.ClientID%>").value;
                var TabId = document.getElementById("<%=hdnPrevTabId.ClientID%>").value;
                var PrevTabIndex = document.getElementById("<%=hdnPrevTabIndex.ClientID%>").value;
                                 
                var elem = document.getElementById("<%= divhidden.ClientID %>").childNodes;
                var TabData = "";
                for (var i = 0; i < elem.length; i++) {
                    if (elem[i].type == "text") {
                        var TabArray = document.getElementById(elem[i].id).id.split(/-/);
                        if (TabArray[4] == TabId) {
                            if (document.getElementById(elem[i].id).value != '0') {
                                TabData = TabData + document.getElementById(elem[i].id).value;
                            }
                        }
                    }

                    else if (elem[i].type == "radio") {
                        var TabArray = document.getElementById(elem[i].id).id.split(/-/);
                        if (TabArray[4] == TabId) {
                            if (document.getElementById(elem[i].id).checked == true) {
                                TabData = TabData + document.getElementById(elem[i].id).value;
                            }
                        }
                    }
                    else if (elem[i].childNodes.length > 0) {
                        if (elem[i].childNodes[0].type == "checkbox") {
                            var TabArray = document.getElementById(elem[i].childNodes[0].id).id.split(/_/);
                            if (TabArray[3] == TabId) {
                                if (document.getElementById(elem[i].childNodes[0].id).checked == true) {
                                    TabData = TabData + document.getElementById(elem[i].childNodes[0].id).value;
                                }
                            }
                        }
                    }

                }
                var PrevTabData=document.getElementById("ctl00_IQCareContentPlaceHolder_hdnStringASCIIValue").value
                if (TabData != PrevTabData) {
                    var userSelectedYesElement = confirm(""+PrevTabName+" Tab has unsaved data. Do you want to save?");
                    //get the hidden field reference:
                    var CurrenttabId = sender.get_activeTab().get_id().split('_');
                    var CurrentTabIndex = sender._activeTabIndex;
                    var CurrentTabName = sender.get_activeTab()._header.innerHTML;
                    CurrenttabId = CurrenttabId[3];
                    document.getElementById("<%=hdnCurrentTabId.ClientID%>").value = CurrenttabId;
                    document.getElementById("<%=hdnSaveTabData.ClientID%>").value = userSelectedYesElement;
                    document.getElementById("<%=hdnCurrenTabName.ClientID%>").value = CurrentTabName;
                    //document.getElementById("<%=hdnCurrenTabIndex.ClientID%>").value = CurrentTabIndex;
                    if (userSelectedYesElement) {
                        document.getElementById("<%=hdnCurrenTabIndex.ClientID%>").value = CurrentTabIndex;
                        var clickButton = document.getElementById('ctl00_IQCareContentPlaceHolder_TAB_' + TabId + '_btnSave-' + TabId + '');
                        clickButton.click();
                    }
                    else {
                        document.getElementById("<%=hdnPrevTabIndex.ClientID%>").value = CurrentTabIndex;
                        document.getElementById("<%=hdnPrevTabId.ClientID%>").value = CurrenttabId;
                        document.getElementById("<%=hdnPrevTabName.ClientID%>").value = CurrentTabName;
                        if (document.getElementById("<%=hdnVisitId.ClientID%>").value == "0") {
                            ClearTabData(TabId);
                        }
                        else {
                            //window.location.reload() 
                            StringASCII(CurrenttabId);
                        }
                    }

                    //returning what the user selected
                    return userSelectedYesElement;
                }
                else {
                    var CurrenttabId = sender.get_activeTab().get_id().split('_');
                    var CurrentTabName = sender.get_activeTab()._header.innerHTML;
                    var CurrentTabIndex = sender._activeTabIndex;
                    CurrenttabId = CurrenttabId[3];
                    document.getElementById("<%=hdnSaveTabData.ClientID%>").value = false;
                    document.getElementById("<%=hdnPrevTabId.ClientID%>").value = CurrenttabId;
                    document.getElementById("<%=hdnPrevTabName.ClientID%>").value = CurrentTabName;
                    document.getElementById("<%=hdnPrevTabIndex.ClientID%>").value = CurrentTabIndex;
                    StringASCII(CurrenttabId);
                }
            }
        </script>
        <div id="DIVCustomForm" runat="server">
            <h1 class="margin" id="Header" runat="server" visible="false">
            </h1>
            <div id="DivVisitDate" class="border center formbg" runat="server">
                <table id="tbl1" cellspacing="6" cellpadding="0" width="100%" border="0" runat="server">
                    <tbody>
                        <tr>
                            <td class="form" align="center" valign="top" colspan="2">
                                <label class="required" for="VisitDate" id="lblvisitdate">
                                    <asp:Label ID="Label1" runat="server" Text="Visit Date:"></asp:Label>
                                </label>
                                <asp:TextBox ID="txtvisitDate" MaxLength="11" runat="server" Width="8%"></asp:TextBox>
                                <img id="Img8" onclick="w_displayDatePicker('<%= txtvisitDate.ClientID %>');" height="22"
                                    alt="Date Helper" hspace="3" src="../images/cal_icon1.gif" width="22" border="0" style="vertical-align:middle;" />
                                <span class="smallerlabel">(DD-MMM-YYYY)</span>
                                <asp:HiddenField ID="hdnVisitData" runat="server" />
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <br />
            <%--<act:TabContainer ID="tabcontainer" runat="server" AutoPostBack="True"
                  OnClientActiveTabChanged="ValidateSave1()"  OnActiveTabChanged="tabcontainer_ActiveTabChanged"></act:TabContainer>--%>
            <%--<act:TabContainer ID="tabControl" runat="server" Height="500px" ActiveTabIndex="0"
            CssClass="ajax__tab_technorati-theme"> </act:TabContainer>
            <act:TabPanel ID="tbpnlgeneral" runat="server" Font-Size="Medium" HeaderText="General">
                <HeaderTemplate>
                    General
                </HeaderTemplate>
                <ContentTemplate>
                </ContentTemplate>
            </act:TabPanel>--%>
            <asp:Panel class="border formbg" align="left" ID="PnlforTab" runat="server" Width="100%">
                <br />
            </asp:Panel>
            <br />
            <%-- <asp:Panel class="border center formbg" ID="DIVCustomItem" runat="server">
            <br />
        </asp:Panel>
        <br />--%>
            <div class="border center formbg">
                <table cellspacing="6" cellpadding="0" width="100%">
                    <tbody>
                        <tr id="TrSignatureAll" runat="server" visible="false">
                            <td class="form" align="center" valign="top" colspan="2">
                                <label for="VisitDate">
                                    Signature:</label>
                                <asp:DropDownList ID="ddSignature" runat="server">
                                </asp:DropDownList>
                            </td>
                        </tr>
                        <tr>
                            <asp:TextBox ID="txtSysDate" runat="server" CssClass="textstylehidden"></asp:TextBox>
                            <td class="form" align="center">
                                <asp:HiddenField ID="hdfldDOB" runat="server" />
                                <asp:HiddenField ID="theHitCntrl" runat="server" />
                                <asp:HiddenField ID="hdnPrevTabId" runat="server" />
                                <asp:HiddenField ID="hdnCurrentTabId" runat="server" />
                                <asp:HiddenField ID="hdnPrevTabIndex" runat="server" />
                                <asp:HiddenField ID="hdnCurrenTabIndex" runat="server" />
                                <asp:HiddenField ID="hdnSaveTabData" runat="server" />
                                <asp:HiddenField ID="hdnStringASCIIValue" runat="server" />
                                <asp:HiddenField ID="hdnVisitId" runat="server" />
                                <asp:HiddenField ID="hdnPrevTabName" runat="server" />
                                <asp:HiddenField ID="hdnCurrenTabName" runat="server" />
                                <asp:Button ID="btnsave" Text="Save" runat="server" Visible="false" OnClick="btnsave_Click" />
                                <asp:Button ID="btncomplete" runat="server" Visible="false" Text="Data Quality Check"
                                    OnClick="btncomplete_Click" />
                                <asp:Button ID="btnCancel" Text="Close" runat="server" OnClick="btnCancel_Click">
                                </asp:Button>
                                <asp:Button ID="btnPrint" Text="Print All"  Visible="false" runat="server" OnClientClick="WindowPrintAll()" />
                            </td>
                        </tr>
                        <%-- <asp:HiddenField ID="hidautoSingleLineID" runat="server" />
                    <asp:HiddenField ID="hidautoDecimalID" runat="server" />
                    <asp:HiddenField ID="hidautoNumericID" runat="server" />
                    <asp:HiddenField ID="hidautoDropdownID" runat="server" />
                    <asp:HiddenField ID="hidautoDateID" runat="server" />
                    <asp:HiddenField ID="hidautoMultiLineID" runat="server" />
                    <asp:HiddenField ID="hidautoSingleLineValue" runat="server" />
                    <asp:HiddenField ID="hidautoDecimalValue" runat="server" />
                    <asp:HiddenField ID="hidautoNumericValue" runat="server" />
                    <asp:HiddenField ID="hidautoDropdownValue" runat="server" />
                    <asp:HiddenField ID="hidautoDateValue" runat="server" />
                    <asp:HiddenField ID="hidautoMultiLineValue" runat="server" />--%>
                    </tbody>
                </table>
            </div>
        </div>
        <div id="divhidden" runat="server" style="display: none">
        </div>
    </div>
</asp:Content>
